home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / go / prog / nextgo23.taz / nextgo23 / NeXTGo / findnext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  2.7 KB  |  154 lines

  1. #include "comment.header"
  2.  
  3. #define EMPTY 0
  4.  
  5. extern unsigned char p[19][19], ma[19][19];
  6. extern int currentStone, MAXX, MAXY;
  7. extern int lib;
  8. extern countlib(int,int,int);
  9.  
  10. int fval(int newlib, int minlib)
  11.      /* evaluate new move */
  12. {
  13.   int k, val;
  14.   
  15.   if (newlib <= minlib)
  16.     val = -1;
  17.   else
  18.     {
  19.       k = newlib - minlib;
  20.       val = 40 + (k - 1) * 50 / (minlib * minlib * minlib);
  21.     }
  22.   return val;
  23. }  /* end fval */
  24.  
  25.  
  26. int findnextmove(int m, int n, int *i, int *j, int *val, int minlib)
  27.      /* find new move i, j from group containing m, n */
  28. {
  29.   int ti, tj, tval;
  30.   int found = 0;
  31.   
  32.   *i = -1;   *j = -1;    *val = -1;
  33.   /* mark current position */
  34.   ma[m][n] = 1;
  35.   
  36.   /* check North neighbor */
  37.   if (m != 0)
  38.     if (p[m - 1][n] == EMPTY)
  39.       {
  40.     ti = m - 1;
  41.     tj = n;
  42.     lib = 0;
  43.     countlib(ti, tj, currentStone);
  44.     tval = fval(lib, minlib);
  45.     found = 1;
  46.       }
  47.     else
  48.       if ((p[m - 1][n] == currentStone) && !ma[m - 1][n])
  49.     if (findnextmove(m - 1, n, &ti, &tj, &tval, minlib))
  50.       found = 1;
  51.   
  52.   if (found)
  53.     {
  54.       found = 0;
  55.       if (tval > *val)
  56.     {
  57.       *val = tval;
  58.       *i = ti;
  59.       *j = tj;
  60.     }
  61.       if (minlib == 1) return 1;
  62.     }
  63.   
  64.   /* check South neighbor */
  65.   if (m != MAXY - 1)
  66.     if (p[m + 1][n] == EMPTY)
  67.       {
  68.     ti = m + 1;
  69.     tj = n;
  70.     lib = 0;
  71.     countlib(ti, tj, currentStone);
  72.     tval = fval(lib, minlib);
  73.     found = 1;
  74.       }
  75.     else
  76.       if ((p[m + 1][n] == currentStone) && !ma[m + 1][n])
  77.     if (findnextmove(m + 1, n, &ti, &tj, &tval, minlib))
  78.       found = 1;
  79.   
  80.   if (found)
  81.     {
  82.       found = 0;
  83.       if (tval > *val)
  84.     {
  85.       *val = tval;
  86.       *i = ti;
  87.       *j = tj;
  88.     }
  89.       if (minlib == 1) return 1;
  90.     }
  91.   
  92.   /* check West neighbor */
  93.   if (n != 0)
  94.     if (p[m][n - 1] == EMPTY)
  95.       {
  96.     ti = m;
  97.     tj = n - 1;
  98.     lib = 0;
  99.     countlib(ti, tj, currentStone);
  100.     tval = fval(lib, minlib);
  101.     found = 1;
  102.       }
  103.     else
  104.       if ((p[m][n - 1] == currentStone) && !ma[m][n - 1])
  105.     if (findnextmove(m, n - 1, &ti, &tj, &tval, minlib))
  106.       found = 1;
  107.   
  108.   if (found)
  109.     {
  110.       found = 0;
  111.       if (tval > *val)
  112.     {
  113.       *val = tval;
  114.       *i = ti;
  115.       *j = tj;
  116.     }
  117.       if (minlib == 1) return 1;
  118.     }
  119.   
  120.   /* check East neighbor */
  121.   if (n != MAXX - 1)
  122.     if (p[m][n + 1] == EMPTY)
  123.       {
  124.     ti = m;
  125.     tj = n + 1;
  126.     lib = 0;
  127.     countlib(ti, tj, currentStone);
  128.     tval = fval(lib, minlib);
  129.     found = 1;
  130.       }
  131.     else
  132.       if ((p[m][n + 1] == currentStone) && !ma[m][n + 1])
  133.     if (findnextmove(m, n + 1, &ti, &tj, &tval, minlib))
  134.       found = 1;
  135.   
  136.   if (found)
  137.     {
  138.       found = 0;
  139.       if (tval > *val)
  140.     {
  141.       *val = tval;
  142.       *i = ti;
  143.       *j = tj;
  144.     }
  145.       if (minlib == 1) return 1;
  146.     }
  147.   
  148.   if (*val > 0)    /* found next move */
  149.     return 1;
  150.   else    /* next move failed */
  151.     return 0;
  152. }  /* end findnextmove */
  153.  
  154.